<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Subcribe extends Controller
{
	private $_template_f;
	private $_lang;
	private $_numShowItem = 50;
	function __construct()
	{
		parent::Controller();
		$this->_lang = $this->mycommon->getLangCode();
		$this->_template_f = $this->config->item('template_f');
		
		$this->load->language('common', $this->_lang);
		$common_lang = $this->lang->line('common_lang');
		if(!$this->session->userdata('uname'))
		{
			redirect(site_url('/login'));
			die();
		}
		else
		{
			$permitid = $this->session->userdata('permitid');
			if(!is_numeric($permitid) || $permitid > -1)
			{
				show_error($common_lang['access_denied']);
				die();
			}
		}
		
		$this->load->model('subcribe/subcribe_model');	
	}
	
	function _loadHeader($title = '')
	{
		$header = array();
		$header['title'] = $title;
		$header['template_f'] = $this->_template_f;
		
		$header['username'] = '';
		$header['userid'] = '';
		$header['permitid'] = '';
		$header['lang'] = $this->_lang;
		$header['module_name'] = 'subcribe';
		if($this->session->userdata('uname'))
		{
			$header['username'] = $this->session->userdata('uname');
			$header['userid'] = $this->session->userdata('uid');
			$header['permitid'] = $this->session->userdata('permitid');
		}
		// load header
		$this->load->view($this->_template_f . 'preheader_view');
		$this->load->view($this->_template_f . 'header_view', $header);
	}
	
	function _loadMenu()
	{
		$data = array();
		$data['username'] = '';
		$data['userid'] = '';
		$data['permitid'] = '';
		$data['lang'] = $this->_lang;
		if($this->session->userdata('uname'))
		{
			$data['username'] = $this->session->userdata('uname');
			$data['userid'] = $this->session->userdata('uid');
			$data['permitid'] = $this->session->userdata('permitid');
		}
		$data['common_lang'] = $this->lang->line('common_lang');
		
		$this->load->view($this->_template_f . 'menu_view', $data);
	}
	
	function _loadFooter()
	{
		$this->load->view($this->_template_f . 'footer_view');
	}
	
	function view()
	{
		// load header
		$this->_loadHeader('Quản lý Subcribe Email');
		
		// load menu
		$this->_loadMenu();
		
		$status = $this->mycommon->getSaveSqlStr($this->input->get('status'));
		$status = ($status != '-1' && $status != '0' && $status != '1') ? '-1' : $status;
		
		$cPage = $this->mycommon->getSaveSqlStr($this->input->get('cpage'));
		$cPage = is_numeric($cPage) && $cPage > 0 ? $cPage : 1;
		
		$data = array();
		$data = $this->subcribe_model->get_list($status, $cPage, $this->_numShowItem);
		
		$data['lstPaging'] = $this->mycommon->getListPaging($cPage, $data['pCount']);
		
		$data['status'] = $status;
		$data['cPage'] = $cPage;
		
		$this->load->view($this->_template_f . 'subcribe/list_view', $data);
		
		// load footer
		$this->_loadFooter(); 
		
	}
	
	function webmaster()
	{
		$cPage = $this->mycommon->getSaveSqlStr($this->input->get('cpage'));
		$cPage = is_numeric($cPage) && $cPage > 0 ? $cPage : 1;
		
		$data = array();
		$data = $this->subcribe_model->get_list_webmaster($cPage, $this->_numShowItem);
		
		$data['lstPaging'] = $this->mycommon->getListPaging($cPage, $data['pCount']);
		
		$data['cPage'] = $cPage;
		
		$export = $this->input->get('exp');
		if($export == 'excel')
		{
			$this->load->view($this->_template_f . 'subcribe/list_webmaster_excel_view', $data, true);
		}
		
		// load header
		$this->_loadHeader('Quản lý Webmaster subcribe');
		
		// load menu
		$this->_loadMenu();
		
		$this->load->view($this->_template_f . 'subcribe/list_webmaster_view', $data);
		
		// load footer
		$this->_loadFooter(); 
	}
}